<?php
	//digunakan untuk kelas untuk permintaan yang tidak biasa
	class BIRD_MODEL extends CI_Model{
		var $temp =0;
		/**
		*	@param Pigeon, 
		*	I:	intid_week,
		*	O:	query->result
		* 	Desc: untuk melihat laporan totalomset per-week dari seluruh cabang
		*/
		function Pigeon($week){
		
			/*
			$query = $this->db->query('SELECT *,
				(select sum(n.inttotal_omset) totalomset from nota n where n.intid_cabang = c.intid_cabang and n.intid_week = "$week") totalomset 
				from cabang c
				where c.intid_cabang !="" and c.intid_cabang != 1');
			return $query->result();
			/*
			select sum(n.inttotal_omset) from nota n where n.intid_cabang = c.intid_cabang  
			*/
			$query = $this->db->query('SELECT strnama_cabang,
				(select sum(n.inttotal_omset)as totalomset from nota n where n.intid_cabang = c.intid_cabang and n.intid_week = "'.$week.'") totalomset 
				from cabang c
				where c.intid_cabang !="" and c.intid_cabang != 1');
			return $query->result();
			
		}
		/**
		*	@param WoodPecker_Melanerpes, 
		*	I:	intid_week,
		*	O:	query->result
		* 	Desc: untuk melihat laporan semua omset per-week dari seluruh cabang
		*/
		/*
		function WoodPecker_Melanerpes($week){
		//////isinya sma dengan sales mingguan tapi semua cabang dimunculin.
		$this->temp = 'select
				(SELECT SUM(nota.inttotal_omset) FROM nota
				WHERE nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'") inttotal_omset,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_dp != 1 
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1 ) intomset10Reguler,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_dp != 1 
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1)intomset20Reguler,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1 ) intomset10Arisan,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1)intomset20Arisan,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.intid_jpenjualan = 2 ) intomset10ChallHut,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 2 )intomset20ChallHut,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.intid_jpenjualan = 3 ) intomset10Challange,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 3 )intomset20Challange,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.intid_jpenjualan = 4 ) intomset10TradeIn,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 4 )intomset20TradeIn,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.intid_jpenjualan = 5 ) intomset101free1net,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 5 )intomset201free1net,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.intid_jpenjualan = 6 ) intomset101free110prs,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 6 )intomset201free110prs,				
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				AND nota.intid_jpenjualan = 7) omsetnetto, 
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				AND nota.intid_jpenjualan = 11) omsetspecialprice,
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 12) omsetpoint,
				(SELECT sum(nota.inttotal_bayar) 
				FROM nota
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 10) omsetsk,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and nota.intid_week = "'.$week.'"
				and nota.intid_cabang = c.intid_cabang
				and nota.is_arisan = 0
				and nota.is_dp = 0
				and barang.intid_jbarang=5) omsetlg,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and nota.intid_week = "'.$week.'"
				and nota.intid_cabang = c.intid_cabang
				and barang.intid_jbarang=6
				and nota.is_arisan = 0
				and nota.is_dp = 0) omsetll,
				(select sum(inttotal_bayar) from nota where 
				nota.intid_cabang = c.intid_cabang
				and nota.intid_week = "'.$week.'") inttotal_bayar,
				(select sum(intpv) from nota where 
				nota.intid_cabang = c.intid_cabang
				and nota.intid_week = "'.$week.'") intpv,
			c.strnama_cabang 
			from cabang c';
		$query = $this->db->query($this->temp);
	return $query->result();
		}
		*/
	/**
		*	@param WoodPecker_Sphyrapicus, 
		*	I:	intid_week,
		*	O:	query->result
		* 	Desc: untuk melihat laporan semua omset per-bulan dari seluruh cabang
		*/
		/*
		function WoodPecker_Sphyrapicus($month){
		//////isinya sma dengan sales Bulanan tapi semua cabang dimunculin.
		$this->temp = 'select
				(SELECT SUM(nota.inttotal_omset) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'") inttotal_omset,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1 ) intomset10Reguler,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1)intomset20Reguler,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1 ) intomset10Arisan,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1)intomset20Arisan,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 2 ) intomset10ChallHut,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 2 )intomset20ChallHut,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 3 ) intomset10Challange,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 3 )intomset20Challange,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 4 ) intomset10TradeIn,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 4 )intomset20TradeIn,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'" 
				and nota.intid_jpenjualan = 5 ) intomset101free1net,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 5 )intomset201free1net,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 6 ) intomset101free110prs,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 6 )intomset201free110prs,				
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				AND nota.intid_jpenjualan = 7) omsetnetto, 
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				AND nota.intid_jpenjualan = 11) omsetspecialprice,
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 12) omsetpoint,
				(SELECT sum(nota.inttotal_bayar) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 10) omsetsk,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang, week 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and week.intbulan = "'.$month.'"
				and nota.intid_week = week.intid_week
				and nota.intid_cabang = c.intid_cabang
				and nota.is_arisan = 0
				and nota.is_dp = 0
				and barang.intid_jbarang=5) omsetlg,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang, week 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and week.intbulan = "'.$month.'"
				and nota.intid_week = week.intid_week
				and nota.intid_cabang = c.intid_cabang
				and barang.intid_jbarang=6
				and nota.is_arisan = 0
				and nota.is_dp = 0) omsetll,
				(select sum(inttotal_bayar) from nota inner join week on nota.intid_week = week.intid_week
				where 
				nota.intid_cabang = c.intid_cabang
				and week.intbulan = "'.$month.'") inttotal_bayar,
				(select sum(intpv) from nota inner join week on nota.intid_week = week.intid_week where 
				nota.intid_cabang = c.intid_cabang
				and week.intbulan = "'.$month.'") intpv,
			c.strnama_cabang 
			from cabang c';
		$query = $this->db->query($this->temp);
	return $query->result();
		}
		*/
		/**
		*	@param Grey_Headed_Woodpecker
		*	I:	intid_week,
		*	O:	query->result
		* 	Desc: untuk melihat laporan semua omset per-week dari seluruh cabang
		*/
		function Grey_Headed_Woodpecker($week){
		//////isinya sma dengan sales mingguan tapi semua cabang dimunculin.
		$this->temp = 'select
				(SELECT SUM(nota.inttotal_omset) FROM nota
				WHERE nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'") inttotal_omset,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_dp != 1 
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1 ) intomset10Reguler,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_dp != 1 
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1)intomset20Reguler,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1 ) intomset10Arisan,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1)intomset20Arisan,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.is_dp = 0
				and nota.intid_jpenjualan = 2 ) intomset10ChallHut,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_dp = 0
				and nota.intid_jpenjualan = 2 )intomset20ChallHut,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.is_dp = 0
				and nota.intid_jpenjualan = 3 ) intomset10Challange,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.is_dp = 0
				and nota.intid_jpenjualan = 3 )intomset20Challange,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.is_dp = 0
				and nota.intid_jpenjualan = 4 ) intomset10TradeIn,
				(SELECT SUM(nota.inttotal_bayar) FROM nota
				WHERE  nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intomset20 = 0
				and nota.is_dp = 0
				and nota.intid_jpenjualan = 5 ) intomset101free1net,
				(SELECT SUM(nota.intomset10) FROM nota
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'" 
				and nota.is_dp = 0
				and nota.intid_jpenjualan = 6 ) intomset101free110prs,
				(SELECT SUM(nota.intomset20) FROM nota
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.intid_week = "'.$week.'"
				and nota.intid_jpenjualan = 6 )intomset201free110prs,				
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 7) omsetnetto, 
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND  nota.intid_jpenjualan = 11) omsetspecialprice,
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 12) omsetpoint,
				(SELECT sum(nota.inttotal_bayar) 
				FROM nota
				WHERE nota.intid_week = "'.$week.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_jpenjualan = 10) omsetsk,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and nota.intid_week = "'.$week.'"
				and nota.intid_cabang = c.intid_cabang
				and nota.is_arisan = 0
				and nota.is_dp = 0
				and barang.intid_jbarang=5) omsetlg,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and nota.intid_week = "'.$week.'"
				and nota.intid_cabang = c.intid_cabang
				and barang.intid_jbarang=6
				and nota.is_arisan = 0
				and nota.is_dp = 0) omsetll,
				(select sum(inttotal_bayar) from nota where 
				nota.intid_cabang = c.intid_cabang
				and nota.intid_week = "'.$week.'") inttotal_bayar,
				(select sum(intpv) from nota where 
				nota.intid_cabang = c.intid_cabang
				and nota.is_dp = 0
				and nota.intid_week = "'.$week.'") intpv,
			c.strnama_cabang 
			from cabang c';
		$query = $this->db->query($this->temp);
	return $query->result();
		}
	/**
		*	@param Black_WoodPecker
		*	I:	intid_week,
		*	O:	query->result
		* 	Desc: untuk melihat laporan semua omset per-bulan dari seluruh cabang
		*/
		function Black_WoodPecker($month){
		//////isinya sma dengan sales Bulanan tapi semua cabang dimunculin.
		
		$this->temp = 'select
				(SELECT SUM(nota.inttotal_omset) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'") inttotal_omset,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1 ) intomset10Reguler,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1)intomset20Reguler,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1 ) intomset10Arisan,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1)intomset20Arisan,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 2 ) intomset10ChallHut,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.is_dp != 1 
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 2 )intomset20ChallHut,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.is_dp != 1 
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 3 ) intomset10Challange,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.is_dp != 1 
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 3 )intomset20Challange,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.is_dp != 1 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 4 ) intomset10TradeIn,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 4 )intomset20TradeIn,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE  nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'" 
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 5 ) intomset101free1net,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 5 )intomset201free1net,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 6 ) intomset101free110prs,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 6 )intomset201free110prs,				
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				and nota.is_dp != 1 
				AND nota.intid_jpenjualan = 7) omsetnetto, 
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				and nota.is_dp != 1 
				AND nota.intid_jpenjualan = 11) omsetspecialprice,
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				and nota.is_dp != 1 
				AND nota.intid_jpenjualan = 12) omsetpoint,
				(SELECT sum(nota.inttotal_bayar) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				and nota.is_dp != 1 
				AND nota.intid_jpenjualan = 10) omsetsk,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang, week 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and week.intbulan = "'.$month.'"
				and nota.intid_week = week.intid_week
				and nota.intid_cabang = c.intid_cabang
				and nota.is_arisan = 0
				and nota.is_dp = 0
				and barang.intid_jbarang=5) omsetlg,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang, week 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and week.intbulan = "'.$month.'"
				and nota.intid_week = week.intid_week
				and nota.intid_cabang = c.intid_cabang
				and barang.intid_jbarang=6
				and nota.is_arisan = 0
				and nota.is_dp = 0) omsetll,
				(select sum(inttotal_bayar) from nota inner join week on nota.intid_week = week.intid_week
				where 
				nota.intid_cabang = c.intid_cabang
				and nota.is_dp != 1 
				and week.intbulan = "'.$month.'") inttotal_bayar,
				(select sum(intpv) from nota inner join week on nota.intid_week = week.intid_week where 
				nota.intid_cabang = c.intid_cabang
				and nota.is_dp != 1 
				and week.intbulan = "'.$month.'") intpv,
			c.strnama_cabang 
			from cabang c';
			/*
			$this->temp = 'select
				(SELECT SUM(nota.inttotal_omset) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'") inttotal_omset,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1 ) intomset10Reguler,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.is_arisan != 1 
				and nota.intid_jpenjualan = 1)intomset20Reguler,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1 ) intomset10Arisan,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.is_arisan = 1 
				and nota.intid_jpenjualan = 1)intomset20Arisan,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 2 ) intomset10ChallHut,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.is_dp != 1 
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 2 )intomset20ChallHut,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.is_dp != 1 
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 3 ) intomset10Challange,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and nota.is_dp != 1 
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 3 )intomset20Challange,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.is_dp != 1 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.intid_jpenjualan = 4 ) intomset10TradeIn,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 4 )intomset20TradeIn,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE  nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'" 
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 5 ) intomset101free1net,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 5 )intomset201free1net,
				(SELECT SUM(nota.intomset10) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 5 
				AND nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 6 ) intomset101free110prs,
				(SELECT SUM(nota.intomset20) FROM nota inner join week on nota.intid_week = week.intid_week
				WHERE nota.intid_jpenjualan != 7 
				and nota.intid_cabang = c.intid_cabang  
				and week.intbulan = "'.$month.'"
				and nota.is_dp != 1 
				and nota.intid_jpenjualan = 6 )intomset201free110prs,				
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				and nota.is_dp != 1 
				AND nota.intid_jpenjualan = 7) omsetnetto, 
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				AND nota.intid_cabang != 1
				and nota.is_dp != 1 
				AND nota.intid_jpenjualan = 11) omsetspecialprice,
				(SELECT SUM(nota_detail.intquantity*nota_detail.intharga) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				and nota.is_dp != 1 
				AND nota.intid_jpenjualan = 12) omsetpoint,
				(SELECT sum(nota.inttotal_bayar) 
				FROM nota INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang INNER JOIN week on nota.intid_week = week.intid_week
				WHERE week.intbulan = "'.$month.'"
				AND nota.intid_cabang = c.intid_cabang
				and nota.is_dp != 1 
				AND nota.intid_jpenjualan = 10) omsetsk,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang, week 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and week.intbulan = "'.$month.'"
				and nota.intid_week = week.intid_week
				and nota.intid_cabang = c.intid_cabang
				and nota.is_arisan = 0
				and nota.is_dp = 0
				and barang.intid_jbarang=5) omsetlg,
				(select sum(nota_detail.intquantity*nota_detail.intharga) 
				from nota, nota_detail, barang, week 
				where nota.intid_nota = nota_detail.intid_nota
				and nota_detail.intid_barang = barang.intid_barang
				and week.intbulan = "'.$month.'"
				and nota.intid_week = week.intid_week
				and nota.intid_cabang = c.intid_cabang
				and barang.intid_jbarang=6
				and nota.is_arisan = 0
				and nota.is_dp = 0) omsetll,
				(select sum(inttotal_bayar) from nota inner join week on nota.intid_week = week.intid_week
				where 
				nota.intid_cabang = c.intid_cabang
				and nota.is_dp != 1 
				and week.intbulan = "'.$month.'") inttotal_bayar,
				(select sum(intpv) from nota inner join week on nota.intid_week = week.intid_week where 
				nota.intid_cabang = c.intid_cabang
				and nota.is_dp != 1 
				and week.intbulan = "'.$month.'") intpv,
			c.strnama_cabang 
			from cabang c';
			*/
		$query = $this->db->query($this->temp);
	return $query->result();
		}
		/**
		*/
		function owl($kode,$week)
			{
				//$week = $this->db->query("select intid_week from week where curdate() between dateweek_start and dateweek_end");
				//$id_week = $week->result();
				//$week_now = $id_week[0]->intid_week;
				$query = $this->db->query("select distinct(a.datetgl) tanggal, a.intno_nota,a.inttotal_omset 
										   from nota a join nota_detail b on a.intid_nota=b.intid_nota 
										   where a.intid_dealer = $kode
										   and a.intid_week = $week
										   and a.is_lg = 0
										   and a.is_dp = 0");
				return $query->result();
			}
			
			function show_temp(){
				$query = $this->db->query('select intid_cabang from cabang ');
				return $query->result();
			}
			/**
		*	@param Golden_Eagle, 
		*	I:	intid_jpenjualan, intbulan, intbulan
		*	O:	query->result
		* 	Desc: penggunaan untuk menampilkan data penjualan setiap unit yang terdaftar di tabel, dengan patokan intid_jpenjualan
		*/
		function Golden_Eagle($jenisPenjualan,$bulanPertama,$bulanKedua){
				//lakukan pencarian
				$var = "";
				if($jenisPenjualan == 1){
					$var = "select sum(nota.inttotal_omset) 
								from nota 
								where (nota.intid_jpenjualan = 1 or nota.intid_jpenjualan = 9) 
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 2){
						$var = "select sum(nota.inttotal_omset) 
								from nota 
								where nota.intid_jpenjualan = 2 
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 3){
						$var = "select sum(nota.inttotal_omset) 
								from nota 
								where nota.intid_jpenjualan = 3 
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 4){
						$var = "select sum(nota.inttotal_omset) 
								from nota 
								where nota.intid_jpenjualan = 4 
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 5){
						$var = "select sum(nota.inttotal_omset) 
								from nota 
								where nota.intid_jpenjualan = 5 
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 6){
						$var = "select sum(nota.inttotal_omset) 
								from nota 
								where nota.intid_jpenjualan = 6 
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 7){
						$var = "select sum(nota.inttotal_omset) 
								from nota 
								where nota.intid_jpenjualan = 7 
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 8){
						$var = "select sum(nota.inttotal_bayar) 
								from nota 
								where nota.intid_jpenjualan = 7 
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 9){
						$var = "select sum(nota.inttotal_omset) 
								from nota 
								where (nota.intid_jpenjualan = 9 or nota.intid_jpenjualan = 1) 
								and nota.is_arisan = 1
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 10){
						$var = "select sum(nota.inttotal_bayar) 
								from nota 
								where nota.intid_jpenjualan = 10 
								and nota.is_arisan = 1
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 11){
						$var = "select sum(nota.inttotal_bayar) 
								from nota 
								where nota.intid_jpenjualan = 11
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 12){
						$var = "select sum(nota.inttotal_bayar) 
								from nota 
								where nota.intid_jpenjualan = 12
								and nota.is_dp = 0";
					}elseif($jenisPenjualan == 13){
						$var = "select sum(nota.inttotal_bayar) 
								from nota 
								where nota.intid_jpenjualan = 13
								and nota.is_dp = 0";
					}
				//semua dijadikan satu string baru di eksekusi	
				$this->temp = "select strnama_unit,
				(select strnama_dealer 
				 	from member 
					where member.intid_unit = unit.intid_unit
					and intlevel_dealer = 1
					and intparent_leveldealer = 0
					group by strkode_dealer) nama_manager, 
				(".$var." 
				 	and nota.intid_unit = unit.intid_unit
					and nota.intid_week in (select intid_week 
												from week where intbulan >= '".$bulanPertama."' and intbulan <= '".$bulanKedua."')) total_penjualan,
				(select strnama_jpenjualan 
				 from jenis_penjualan 
				 where intid_jpenjualan = ".$jenisPenjualan.") strnama_jpenjualan
				from unit";
				$query = $this->db->query($this->temp);
				return $query->result();
			}
		
		function get_CetakPenjualanArisanMingguan($week, $cabang)
	{
		
		$query = $this->db->query("select a.datetgl, a.intno_nota, upper(b.strnama_dealer) strnama_dealer, upper(b.strnama_upline) strnama_upline, 
		upper(d.strnama_unit)strnama_unit,upper(c.strnama_cabang) strnama_cabang, a.intid_week,  
		(select date_format(dateweek_start, '%d %M %Y') AS dateweek_start  from week where intid_week = $week) AS datestart,
		(select date_format(dateweek_end, '%d %M %Y') AS dateweek_end from week where intid_week = $week) AS dateend, 
		c.intid_wilayah, h.intcicilan_jawa, h.intcicilan_luarjawa, 
		h.intum_jawa, h.intum_luarjawa, 
		(select sum(inttotal_omset) from nota where nota.intid_week = $week and nota.intid_jpenjualan = 1 and nota.is_arisan = 1 and nota.intid_nota = a.intid_nota) as inttotal_omset, 
		a.intid_jpenjualan, (select sum(intpv) from nota where nota.intid_week = $week and nota.intid_jpenjualan = 1 and nota.is_arisan = 1 and nota.intid_nota = a.intid_nota)as intpv, 
		sum(e.intquantity)intquantity, (select sum(inttotal_bayar) from nota where nota.intid_week = $week and nota.intid_jpenjualan = 1 and nota.is_arisan = 1 and nota.intid_nota = a.intid_nota) inttotal_bayar,	
		(h.intcicilan_jawa*(sum(e.intquantity))*1) as cicilan, 
		(select sum(intkomisi10) from nota where nota.intid_week = $week and nota.intid_jpenjualan = 1 and nota.is_arisan = 1 and nota.intid_nota = a.intid_nota) as intkomisi10, 
		(select sum(intkomisi20) from nota where nota.intid_week = $week and nota.intid_jpenjualan = 1 and nota.is_arisan = 1 and nota.intid_nota = a.intid_nota) as intkomisi20,
		(select sum(nota_detail.intharga*nota_detail.intquantity) from nota_detail where nota_detail.intid_nota = a.intid_nota) retail
		from nota a, member b, cabang c, unit d, nota_detail e, 
		barang f, harga h
		where a.intid_jpenjualan = 1
		and a.is_arisan = 1
		and e.is_free = 0
		and a.intid_week = $week
		and a.intid_dealer = b.intid_dealer
		and a.intid_nota = e.intid_nota
		and a.intid_cabang = c.intid_cabang
		and a.intid_unit = d.intid_unit
		and e.intid_barang = f.intid_barang
		and f.intid_barang = h.intid_barang
		group by a.intid_nota
		order by d.strnama_unit asc, b.strnama_upline asc");
		return $query->result();
		}
	/* tidak digunakan karena diperbarui lagi..
	// 27AGUSTUS2013 oleh ikhlas 15:15
	function get_CetakPenjualanMingguan($week, $cabang, $jpenjualan)
	{
		$query = $this->db->query("SELECT strnama_dealer, 
				strnama_upline, 
				strnama_cabang, strnama_unit, dateend, datestart, intid_week, intkomisi10, intkomisi20, intpv, inttotal_bayar,
				inttotal_omset, strnama_jpenjualan, 
				intid_jpenjualan, 
				IF(omsett >= v, omsett - v, omsett) AS omsett,
				IF(omsett < v AND omsettc < v, omsetm - v, omsetm) AS omsetm,
				IF(omsett < v AND omsettc >= v, omsettc - v, omsettc) AS omsettc, 
				omsetlg, 
				omsetll,
				tradein_t,
				tradein_m 
				FROM 
					(SELECT strnama_dealer, strnama_upline, UPPER(strnama_cabang) AS strnama_cabang, 
						strnama_unit,
						(SELECT date_format(dateweek_end, '%d %M %Y') AS dateweek_end FROM week WHERE intid_week = $week) AS dateend,
						(SELECT date_format(dateweek_start, '%d %M %Y') AS dateweek_start FROM week WHERE intid_week = $week) AS datestart,
						z.* 
						FROM 
							(SELECT intid_week, 
								intid_cabang,
								a.intid_dealer, 
								intno_nota, 
								SUM(intkomisi10) AS intkomisi10, 
								SUM(intkomisi20) AS intkomisi20, 
								SUM(intpv) AS intpv, 
								SUM(inttotal_bayar) AS inttotal_bayar, 
								SUM(inttotal_omset) AS inttotal_omset, 
								UPPER(strnama_jpenjualan) AS strnama_jpenjualan, 
								a.intid_jpenjualan FROM nota a INNER JOIN jenis_penjualan ON jenis_penjualan.intid_jpenjualan = a.intid_jpenjualan 
							WHERE a.intid_week = $week
								AND a.intid_jpenjualan = $jpenjualan AND a.is_arisan = 0 AND a.is_dp = 0 GROUP BY intid_dealer) 
							AS z 
		INNER JOIN member ON z.intid_dealer = member.intid_dealer INNER JOIN cabang ON z.intid_cabang = cabang.intid_cabang INNER JOIN unit ON member.intid_unit = unit.intid_unit INNER JOIN week ON z.intid_week = week.intid_week) AS x
		INNER JOIN
		(SELECT intid_dealer, 
		SUM(omsett) AS omsett, 
		SUM(omsetm) AS omsetm, 
		SUM(omsettc) AS omsettc, 
		SUM(omsetlg) AS omsetlg, 
		SUM(omsetll) AS omsetll FROM (SELECT intid_dealer, 
			IF(intid_jbarang = 1, totalharga, 0) AS omsett, 
			IF(intid_jbarang = 2, totalharga, 0) AS omsetm, 
			IF(intid_jbarang = 3, totalharga, 0) AS omsettc, 
			IF(intid_jbarang = 5, totalharga, 0) AS omsetlg, 
			IF(intid_jbarang = 6, totalharga, 0) AS omsetll FROM (SELECT intid_dealer, intno_nota, SUM(intquantity * intharga) AS totalharga, intid_jbarang FROM nota a INNER JOIN nota_detail ON a.intid_nota = nota_detail.intid_nota INNER JOIN barang ON barang.intid_barang = nota_detail.intid_barang WHERE a.intid_week = $week AND a.intid_jpenjualan = $jpenjualan AND a.is_arisan = 0 AND a.is_dp = 0 AND nota_detail.is_free = 0 GROUP BY intid_dealer, intid_jbarang) AS y) AS z GROUP BY intid_dealer) AS y
		ON x.intid_dealer = y.intid_dealer
		INNER JOIN
		(SELECT intid_dealer, SUM(intvoucher) AS v FROM nota a WHERE a.intid_week = $week  AND a.intid_jpenjualan = $jpenjualan AND a.is_arisan = 0 AND a.is_dp = 0 GROUP BY intid_dealer) AS z
		ON x.intid_dealer = z.intid_dealer
		
		LEFT JOIN
		(SELECT jbarangt.intid_dealer, jbarangt.hasil AS tradein_t, jbarangm.hasil AS tradein_m FROM 
			(SELECT * FROM 
				(SELECT intid_dealer, barang.intid_jbarang, SUM(intharga * intquantity * (1 - (inttrade_in * 0.01))) AS hasil, intid_cabang 
				FROM `nota` INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota 
				INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang 
		WHERE intid_week = $week AND intid_jpenjualan = $jpenjualan
			GROUP BY intid_dealer, intid_jbarang) AS asd 
	WHERE intid_jbarang = 1) AS jbarangt 
INNER JOIN 
	(SELECT * FROM 
		(SELECT intid_dealer, barang.intid_jbarang, SUM(intharga * intquantity * (1 - (inttrade_in * 0.01))) AS hasil, intid_cabang 
		FROM `nota` INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota 
		INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang 
		WHERE intid_week = $week AND intid_jpenjualan = $jpenjualan 
		GROUP BY intid_dealer, intid_jbarang) AS asd 
	WHERE intid_jbarang = 2) AS jbarangm 
ON jbarangt.intid_dealer = jbarangm.intid_dealer
	) AS kodebwtmisahinomsettulipdenganmetal
ON z.intid_dealer = kodebwtmisahinomsettulipdenganmetal.intid_dealer
");
        return $query->result();
	}
	*/
	function get_CetakPenjualanMingguan($week, $cabang, $jpenjualan)
	{
		$query = $this->db->query("SELECT strnama_dealer, 
		strnama_upline, 
		strnama_cabang, strnama_unit, dateend, datestart, intid_week, intkomisi10, intkomisi20, intpv, inttotal_bayar,
		inttotal_omset, strnama_jpenjualan, 
		intid_jpenjualan, 
		IF(omsett >= v, omsett - v, IF(omsetm < omsett AND omsettc < omsett AND omsett < v, 0, omsett)) AS omsett,
		IF(omsett < v AND omsettc < v, omsetm - v, IF(omsett < omsetm AND omsettc < omsetm AND omsetm < v, 0, omsetm)) AS omsetm,
		IF(omsett < v AND omsettc >= v, omsettc - v, IF(omsett < omsettc AND omsetm < omsettc AND omsettc < v, 0, omsettc)) AS omsettc, 
		omsetlg, 
		omsetll,
		tradein_t,
		tradein_m,
		strnama_cabang
		FROM 
			(SELECT strnama_dealer, strnama_upline, UPPER(strnama_cabang) AS strnama_cabang, 
				strnama_unit,
				(SELECT date_format(dateweek_end, '%d %M %Y') AS dateweek_end FROM week WHERE intid_week = $week) AS dateend,
				(SELECT date_format(dateweek_start, '%d %M %Y') AS dateweek_start FROM week WHERE intid_week = $week) AS datestart,
				z.* 
				FROM 
					(SELECT intid_week, 
						intid_cabang,
						a.intid_dealer, 
						intno_nota, 
						SUM(intkomisi10) AS intkomisi10, 
						SUM(intkomisi20) AS intkomisi20, 
						SUM(intpv) AS intpv, 
						SUM(inttotal_bayar) AS inttotal_bayar, 
						SUM(inttotal_omset) AS inttotal_omset, 
						UPPER(strnama_jpenjualan) AS strnama_jpenjualan, 
						a.intid_jpenjualan FROM nota a INNER JOIN jenis_penjualan ON jenis_penjualan.intid_jpenjualan = a.intid_jpenjualan 
					WHERE a.intid_week = $week 
						AND a.intid_jpenjualan = $jpenjualan AND a.is_arisan = 0 AND a.is_dp = 0 GROUP BY intid_dealer) 
					AS z 
INNER JOIN member ON z.intid_dealer = member.intid_dealer INNER JOIN cabang ON z.intid_cabang = cabang.intid_cabang INNER JOIN unit ON member.intid_unit = unit.intid_unit INNER JOIN week ON z.intid_week = week.intid_week
) AS x
INNER JOIN
(SELECT intid_dealer, 
SUM(omsett) AS omsett, 
SUM(omsetm) AS omsetm, 
SUM(omsettc) AS omsettc, 
SUM(omsetlg) AS omsetlg, 
SUM(omsetll) AS omsetll FROM (SELECT intid_dealer, 
	IF(intid_jbarang = 1, totalharga, 0) AS omsett, 
	IF(intid_jbarang = 2, totalharga, 0) AS omsetm, 
	IF(intid_jbarang = 3, totalharga, 0) AS omsettc, 
	IF(intid_jbarang = 5, totalharga, 0) AS omsetlg, 
	IF(intid_jbarang = 6, totalharga, 0) AS omsetll FROM (SELECT intid_dealer, intno_nota, SUM(intquantity * intharga) AS totalharga, intid_jbarang FROM nota a INNER JOIN nota_detail ON a.intid_nota = nota_detail.intid_nota INNER JOIN barang ON barang.intid_barang = nota_detail.intid_barang WHERE a.intid_week = $week AND 
	a.intid_jpenjualan = $jpenjualan AND a.is_arisan = 0 AND a.is_dp = 0 AND nota_detail.is_free = 0 GROUP BY intid_dealer, intid_jbarang) AS y) AS z GROUP BY intid_dealer) AS y
ON x.intid_dealer = y.intid_dealer
INNER JOIN
(SELECT intid_dealer, SUM(intvoucher) AS v FROM nota a WHERE a.intid_week = $week AND a.intid_jpenjualan = $jpenjualan AND a.is_arisan = 0 AND a.is_dp = 0 GROUP BY intid_dealer) AS z
ON x.intid_dealer = z.intid_dealer

LEFT JOIN
(SELECT jbarangt.intid_dealer, jbarangt.hasil AS tradein_t, jbarangm.hasil AS tradein_m FROM 
	(SELECT * FROM 
		(SELECT intid_dealer, barang.intid_jbarang, SUM(intharga * intquantity * (1 - (inttrade_in * 0.01))) AS hasil, intid_cabang 
		FROM `nota` INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota 
		INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang 
		WHERE intid_week = $week AND intid_jpenjualan = $jpenjualan
			GROUP BY intid_dealer, intid_jbarang,intid_cabang) AS asd 
	WHERE intid_jbarang = 1) AS jbarangt 
INNER JOIN 
	(SELECT * FROM 
		(SELECT intid_dealer, barang.intid_jbarang, SUM(intharga * intquantity * (1 - (inttrade_in * 0.01))) AS hasil, intid_cabang 
		FROM `nota` INNER JOIN nota_detail ON nota.intid_nota = nota_detail.intid_nota 
		INNER JOIN barang ON nota_detail.intid_barang = barang.intid_barang 
		WHERE intid_week = $week AND intid_jpenjualan = $jpenjualan 
		GROUP BY intid_dealer, intid_jbarang) AS asd 
	WHERE intid_jbarang = 2) AS jbarangm 
ON jbarangt.intid_dealer = jbarangm.intid_dealer
	) AS kodebwtmisahinomsettulipdenganmetal
ON z.intid_dealer = kodebwtmisahinomsettulipdenganmetal.intid_dealer


");
        return $query->result();
	}
		function get_CetakPenjualanSKMingguan($week, $cabang)
	{
		$query = $this->db->query("select a.datetgl, a.intno_nota, upper(b.strnama_dealer) strnama_dealer, upper(b.strnama_upline) strnama_upline, 
		upper(d.strnama_unit)strnama_unit,upper(c.strnama_cabang) strnama_cabang, a.intid_week,  
		(select date_format(dateweek_start, '%d %M %Y') AS dateweek_start  from week where intid_week = $week) AS datestart,
		(select date_format(dateweek_end, '%d %M %Y') AS dateweek_end from week where intid_week = $week) AS dateend, 
		f.strnama, e.intquantity, h.intharga_jawa, h.intharga_luarjawa, c.intid_wilayah, sum(a.inttotal_bayar)inttotal_bayar 
		from nota a inner join cabang c on c.intid_cabang = a.intid_cabang
		inner join member b on b.intid_dealer = a.intid_dealer
		inner join unit d on d.intid_unit = b.intid_unit,
		nota_detail e, barang f, jenis_barang g, harga h
		where a.intid_nota = e.intid_nota
		and e.intid_barang = f.intid_barang
		and f.intid_jbarang = g.intid_jbarang
		and f.intid_barang = h.intid_barang
		and a.intid_week = $week
		and a.intid_jpenjualan = 10
		and e.is_free = 0
		group by a.datetgl, a.intno_nota, b.strnama_dealer, b.strnama_upline, d.strnama_unit,
		d.strnama_unit, a.intid_week, f.strnama, e.intquantity, h.intharga_jawa, h.intharga_luarjawa, c.intid_wilayah
		order by d.strnama_unit asc, b.strnama_upline asc");
        return $query->result();
	}
	
	}
?>